package com.block.api.controller.source;

import com.alibaba.fastjson.JSONObject;
import com.block.common.security.util.ApiUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import com.block.source.service.ISourceCheckUserService;
import com.block.source.service.ISourcePushResultInfoService;
import com.block.source.service.ISourceRegisterUserService;
import com.block.source.service.ISourceResultHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/source")
public class SourceInnerController {

    @Autowired
    ISourceCheckUserService sourceCheckUserService;
    @Autowired
    ISourceRegisterUserService sourceRegisterUserService;
    @Autowired
    ISourcePushResultInfoService sourcePushResultInfoService;
    @Autowired
    ISourceResultHandleService sourceResultHandleService;

    @RequestMapping(value = "/getOrderInfo", method = {RequestMethod.POST})
    public String getOrderInfo(@RequestAttribute(value = "tranData") JSONObject tranData,
                               @RequestAttribute(value = "uri") String uri,
                               @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                               @RequestAttribute(value = "startDate") Date startdate,
                               @RequestAttribute(value = "ip") String ip) {

        String resultNo = tranData.getString("resultNo");

        ResponseVo responseVo = sourcePushResultInfoService.getOrderInfo(resultNo);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt, startdate, uri);
    }

    @RequestMapping(value = "/approveToPush", method = {RequestMethod.POST})
    public String approveToPush(@RequestAttribute(value = "tranData") JSONObject tranData,
                                @RequestAttribute(value = "uri") String uri,
                                @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                                @RequestAttribute(value = "startDate") Date startdate,
                                @RequestAttribute(value = "ip") String ip) {

        String resultNo = tranData.getString("resultNo");

        ResponseVo responseVo = sourceResultHandleService.approveToPush(resultNo, ip);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt, startdate, uri);
    }

}